/**
 * created by 小卷毛, 2020/10/23
 * Copyright (c) 2020, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.sgcc.pda.mdrh.task.util

import android.content.ComponentName
import android.content.ServiceConnection
import android.os.IBinder
import com.sgcc.pda.tools.LogPrintUtils

/**
 * 描 述：
 * 作 者：小卷毛  2020-10-23 14:59
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
open class ConnectionListener : ServiceConnection {

    private var _onServiceConnected: ((ComponentName, IBinder) -> Unit)? = null
    private var _onServiceDisconnected: ((ComponentName) -> Unit)? = null

    fun onServiceConnected(listener: (ComponentName, IBinder) -> Unit) {
        _onServiceConnected = listener
    }

    fun onServiceDisconnected(listener: (ComponentName) -> Unit) {
        _onServiceDisconnected = listener
    }

    override fun onServiceConnected(name: ComponentName, iBinder: IBinder) {
        LogPrintUtils.i("绑定服务成功！")
        _onServiceConnected?.invoke(name, iBinder)
    }

    override fun onServiceDisconnected(name: ComponentName) {
        LogPrintUtils.i("解绑服务成功！")
        _onServiceDisconnected?.invoke(name)
    }

}